var e = require("../../@babel/runtime/helpers/slicedToArray");
require("../../@babel/runtime/helpers/Objectentries");
var t, o = (t = require("@vant/weapp/toast/toast")) && t.__esModule ? t : {
    default: t
};
var a = require("../../utils/request"), r = require("../../utils/storage"), s = require("../../utils/util");

Page({
    data: { 
        checked: !1, 
        path: "",
        active: "",  
        showDialog: !1,
        phone:''
    },
    onLoad: function(e) {
        console.log(e), this.setData({
            path: e.path,
            active: e.active, 
        }); 
         
    },
 
   
    
   
    
    onChange: function(e) {
        this.setData({
            checked: e.detail
        });
    },
   
    goredirectTo: function() {
      console.log(333)
        var t = this.data.path, o = (this.data.active, this.data.cardNo), a = this.data.reservationNo;
        if ("check" == t) wx.redirectTo({
            url: "/pages/myhoscheck/myhoscheck"
        }); else if ("report" == t) wx.switchTab({
            url: "/pages/myreport/myreport"
        }); else if ("my" == t) wx.switchTab({
            url: "/pages/my/my"
        });    else wx.navigateBack({
            delta: 1
        });
    },
     
    // 获取手机号
    getPhoneNumber: function(e) {
      var t = this;
      
                 
                  var s = r.getStorageSync(r.storageKey.openId);
                  if("getPhoneNumber:ok" == e.detail.errMsg){
                    a.post1('/wechat/Apiwechat/wxtel', {
                      sessionKey: wx.getStorageSync("sessionKey"),
                      encryptedData: e.detail.encryptedData,
                      iv: e.detail.iv,
                      openId: s
                  }).then(function(e) {
                      wx.hideLoading();
                      if("1" == e.code){          
                        wx.setStorageSync("phoneNumber", e.data.phoneNumber);
                        t.setData({phone:e.data.phoneNumber});  
                        console.log(e.data.phoneNumber);
                        t.onSubmitphone(); 
                        r.setStorage(r.storageKey.phoneNumber, e.data.phoneNumber);
                        t.goredirectTo();
                      }else{
                        wx.hideLoading();                  
            
                      }
                  })
                }
               
               
         
  },

  onSubmitphone(){
    let that=this;  
    console.log("phonefanxie",that.data.phone)
    if(!that.data.phone){
      return wx.showToast({
        title: '缺少手机号',
        icon: 'none'
      })
    }
    wx.showLoading();
   // 更新手机号
    a.post1("/wechat/home/setMemberInfo", {
        mobile:that.data.phone,
        flag: 2,
        openid:wx.getStorageSync("openid")
    }).then(function(e) {

        if ("1" == e.code) {

            wx.hideLoading();
            // that.setData({show:false});
            wx.showToast({
              title: '登录成功！',
              icon: 'success'
            })
 
           that.getUinfo(); 
        };


    })
    

  },

  getUinfo: function() {
    let that=this;  
    
    wx.showLoading({
        title: "正在加载中..."
    });
    var t = wx.getStorageSync('openid');

        a.post1("/wechat/Member/getUserInfo", {
            openid: t
        }).then(function(fh) {
        if (wx.hideLoading(), "1" == fh.code) {
            var a = fh.data;
            console.log("uinfo",a)
            wx.setStorageSync('userBase', fh.data);
            wx.setStorageSync('uid',fh.data.id);
            wx.setStorageSync('phoneNumber', fh.data.mobile);
 
              if( fh.data.alias_nickname&& fh.data.headimgurl){
                // e.setData({avatarUrl:s.wapiwimgURL+ t.data.headimgurl,needlogin:0,nickName: t.data.alias_nickname}); 
              }

           
     
        } else {

            wx.showModal({
                title: "提示",
                content: "暂无数据",
                showCancel: !1
            }); 
        };
    });
},

  wxLogin: function() {
    console.log("wxlogin")
    let that=this;
    // 
    var t = "", n = ""; 
    try {
        t = wx.getStorageSync("openId"), 
        n = wx.getStorageSync("unionId"),
        // formObj
         this.setData({
            "formObj.authThirdToken": t,
            "formObj.authThirdUnionToken": n
        });
    } catch (e) {
        console.log("youwu");
    }
    console.log(this.data.formObj);
    //  
    e.post1("wechat/Apiwechat/wxtel", this.data.formObj).then(function(e) {

        if ("1" == e.code) {
            wx.setStorageSync("phoneNumber", e.data.phoneNumber);
            that.setData({phone:e.data.phoneNumber});  
            console.log(e.data.phoneNumber);
            that.onSubmitphone();      
         
            wx.navigateBack({
                delta: 1
            });
        }
    }, function(e) {
        wx.removeStorageSync("openId"), o.getOpenId(), wx.showToast({
            title: e.data.message[0].message,
            icon: "none",
            duration: 2e3,
            mask: !0
        }), console.log(e);
    });
}
     
    
});